package cn.ven.dao;

import cn.ven.entity.Type;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;

import java.util.List;


@Repository
public class TypeDaoImpl implements TypeDao {

    @Autowired
    MongoTemplate mongoTemplate;




    @Override
    public List<Type> findAll() {
        return mongoTemplate.findAll(Type.class);
    }

    @Override
    public Type findById(String id) {
        Query query =new Query(Criteria.where("id").is(id));
        return mongoTemplate.findById(id,Type.class);
    }

    @Override
    public void addType(Type type) {
        mongoTemplate.insert(type);
    }

    @Override
    public void delType(String id) {
        Query query =new Query(Criteria.where("id").is(id));
        mongoTemplate.remove(query,Type.class);
    }

    @Override
    public Type findTypeByType(String type) {
        Query query=new Query(Criteria.where("type").is(type));
        return mongoTemplate.findOne(query,Type.class);
    }


}
